#if !defined(FLOW_INCLUDED)
#define FLOW_INCLUDED

// 扰动流 UV坐标
float3 FlowUVW (float2 uv, float2 flowVector, float2 jump, float flowOffset, float tiling, float time, bool flowB) {
    float phaseOffset = flowB ? 0.5 : 0;
    float progress = frac(time + phaseOffset);
    float3 uvw;
    uvw.xy = uv - flowVector * (progress + flowOffset);
    uvw.xy *= tiling;
    uvw.xy += phaseOffset;
    uvw.xy += (time - progress) * jump;
    uvw.z = 1 - abs(1 - 2 * progress);
    return uvw;
}

// 定向流 UV坐标
float2 DirectionalFlowUV (float2 uv, float3 flowVectorAndSpeed, float tiling, float time, out float2x2 rotation)
{
    float2 dir = normalize(flowVectorAndSpeed.xy);
    rotation = float2x2(dir.y, dir.x, -dir.x, dir.y);
    uv = mul(float2x2(dir.y, -dir.x, dir.x, dir.y), uv);
    uv.y -= time * flowVectorAndSpeed.z;
    return uv * tiling;
}
#endif